package com.lipaluma.field.mapper;

import java.lang.reflect.Field;

import com.lipaluma.context.Context;
import com.lipaluma.exceptions.CsvParserValidationException;
import com.lipaluma.field.validator.Validator;
import com.lipaluma.xml.mapping.XmlFieldMapping;

/**
 * Implementations of {@link FieldMapper} have to implements {@link FieldValidated} to allows the field mapper to validate the value after his parsing.
 * 
 * @author mario.soares
 */
public interface FieldValidated {

	/**
	 * Set the field as required
	 * @param required
	 */
	void required(boolean required);
	
	/**
	 * Add a new validator in the {@link FieldMapper}
	 * @param validator
	 */
	void addNewValidator(Validator validator);

	/**
	 * init the Validator using annotations
	 * @param context TODO
	 * @param field Field of the target entity
	 */
	void initValidator(Context context, Field field);

	/**
	 * init the Validator using the xml mapping
	 * @param context TODO
	 * @param field Field of the target entity
	 * @param element the xml element
	 */
	void initValidator(Context context, Field field, XmlFieldMapping mapping);


	/**
	 * validate the value parsed. When a validation error occurs, a {@link CsvParserValidationException} will be thrown.
	 * @param value value to validate
	 * @throws CsvParserValidationException thrown when there is at least one error of validation
	 */
	void validateValue(Object value) throws CsvParserValidationException;

	/**
	 * return the field associated
	 * @return field the field
	 */
	Field getField();
}
